import json

data=[]
chunk_size = 512
with open('qg.json', 'w', encoding='utf-8') as output:
    # 遍历每一行
    for index, row in df.iterrows():
        contents = [s.strip() for s in row['答案'].split('。') if s.strip()]
        result_contents = [""]
        for s in contents:
            if len(result_contents[-1]) < chunk_size:
                result_contents[-1] += s
            else:
                # print(f'创建了一个{len(result_contents[-1])}的chuck', result_contents[-1])
                result_contents.append(s)
        # 在这里处理每一行的数据
        # 你可以使用row['column_name']来访问特定列的数据
        # print(f"Row {index}: {row['问题']} - {row['答案']}")
        for r in result_contents:
            data.append({'id': index, 'query': row['问题'], 'content': r+'。'})
    json.dump(data, output, indent=4, ensure_ascii=False)